<?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * @package     Pages Module
 * @author      Matrix Infoline (infolinematrix@gmail.com
 * @copyright   (c) Matrix Infoline
 */

class Change_password extends Frontend_Controller
{

	public function __construct()
	{
		parent::__construct();
		$this->template->set_layout('member_layout');
		$this->template->set_partial('header','header/header');
        $this->template->set_partial('footer','footer/footer');
		
		$this->member_model->check_logedin();
	}

	public function index()
	{
		$data['title'] = "Password Change";
		
		//-- Clear Session Data
		
		$this->template->build('change_password',$data);
		 
	}
	
	function submit() {
			
	if ($this->input->post('verify')) {
			
			$this->form_validation->set_rules('oldPsswrd', 'Old Password');
			$this->form_validation->set_rules('nwPsswrd', 'New Password');
			$this->form_validation->set_rules('cnfrmPsswrd', 'Retype Password', 'xss_clean|matches[nwPsswrd]');
				
			
			if ($this->form_validation->run() == TRUE) {
				if (get_session('mem_password') == trim($this->input->post('oldPsswrd'))) {
					$data=array(
					'password'=>$this->input->post('nwPsswrd'));
			
					$this->db->where('id',get_session('mem_id'));
					$this->db->update('member',$data);
					$msg = "<div class='alert alert-success'> Password Changed Sucessfully Login with new Password....!</div>";
					$this->session->set_flashdata('message', $msg);
					redirect('member/change_password');
		
				} else {
					$msg = "<div class='alert alert-success'> Old password is wrong!</div>";
					$this->session->set_flashdata('message', $msg);
					redirect('member/change_password');
				}
			} else {

				$msg = "<div class='alert alert-success'> Field is empty or new password is mismatched with confirm password! </div>";
				$this->session->set_flashdata('message', $msg);
				redirect('member/change_password');
			}
		}
	}

}
